home *** CD-ROM | disk | FTP | other *** search
- Path: gryphon.phoenix.net!usenet
- From: brucew@phoenix.net (Bruce Wedding)
- Newsgroups: comp.lang.c
- Subject: Re: What is '?' in C mean....?????
- Date: Fri, 05 Jan 1996 01:34:43 GMT
- Organization: BranPaul Systems
- Message-ID: <4chsrp$1sf@gryphon.phoenix.net>
- References: <4cgsa8$bm2@wumpus.cc.uow.edu.au>
- NNTP-Posting-Host: dial101.phoenix.net
- X-Newsreader: Moe's Newsreader
-
- tp86@wumpus.cc.uow.edu.au (PAOPENG THEERADECH) wrote:
-
- > The codes that I saw are;
- > max = x>y ? x:y;
- >
- > and
- >
- > printf("%d", x>y ? x:y);
- >
- >Could anyone here explain to me what is "?" means and what the purpose of using
- >it???.
-
- It is the ternary operator. It evaluates the expression before the ?
- and if true, executes the code following the ?, if false, it executes
- teh code following the :
-
- Your max example could be rewritten like this:
-
- max = x>y ? x:y;
-
- if (x>y)
- max = x;
- else
- max = y;
-
-
- Bruce D. Wedding Have Compiler, Will Travel!
- Perspicacious Progamming Performed Promptly
- Katy, Texas, USA, Planet Earth, Milkyway Galaxy, Known Universe
-
-